home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 001-025 / scopedisk7 / blitlab3 / initialize.c < prev    next >
C/C++ Source or Header  |  1995-03-18  |  6KB  |  201 lines

  1. /*
  2.  *   Initialization module of the blitlab program.
  3.  */
  4. #include "structures.h"
  5. /*
  6.  *   These are the externals we reference.
  7.  */
  8. extern struct Window *mywindow ;
  9. extern struct GfxBase *GfxBase ;
  10. extern struct IntuitionBase *IntuitionBase ;
  11. extern struct RastPort *myrp ;
  12. extern int custscreen ;
  13. /*
  14.  *   We use this memory allocator.
  15.  */
  16. extern short *allocmem() ;
  17. /*
  18.  *   This is the screen we use, if we use a screen.  :-)
  19.  */
  20. static char defaulttitle[] =
  21.     "<< Radical Eye Software . . . or I won't get dressed >>" ;
  22. static struct Screen *myscreen ;
  23. static struct TextFont *font ;
  24. static struct TextAttr myfont = {
  25.    (STRPTR) "topaz.font",
  26.    TOPAZ_EIGHTY,
  27.    0,
  28.    0
  29. };
  30. static struct NewScreen mynewscreen = {
  31.    0,                                         /* left edge */
  32.    0,                                         /* top edge */
  33.    640,                                       /* width */
  34.    200,                                       /* height */
  35.    2,                                         /* depth (change for color?)*/
  36.    1,                                         /* detail pen */
  37.    2,                                         /* block pen */
  38.    HIRES,                                     /* screen mode */
  39.    CUSTOMSCREEN,                              /* type */
  40.    &myfont,                                   /* use default font */
  41.    (UBYTE *)defaulttitle,                     /* title */
  42.    NULL,                                      /* initialize this gadget field */
  43.    NULL } ;                                   /* no bitmap supplied */
  44. static short colorTable[] = { 0x058f, 0x0fff, 0x0000, 0x0555 } ;
  45. static short pointerTable[] = 
  46.     { 0x0000, 0x0000,
  47.       0x0100, 0x0000,
  48.       0x0100, 0x0000,
  49.       0x0100, 0x0000,
  50.       0x0100, 0x0000,
  51.       0x0100, 0x0000,
  52.       0x0380, 0x0280,
  53.       0x0440, 0x0440,
  54.       0xFC7E, 0x0000,
  55.       0x0440, 0x0440,
  56.       0x0380, 0x0280,
  57.       0x0100, 0x0000,
  58.       0x0100, 0x0000,
  59.       0x0100, 0x0000,
  60.       0x0100, 0x0000,
  61.       0x0100, 0x0000,
  62.       0x0000, 0x0000 } ;
  63. /*
  64.  *   This is the humongous window we open on the standard
  65.  *   workbench screen.
  66.  */
  67. static struct NewWindow mynewwindow = {
  68.    HWINSTART, VWINSTART, HWINSIZE, VWINSIZE,
  69.    -1, -1,
  70.    MOUSEBUTTONS | MOUSEMOVE | GADGETDOWN | GADGETUP | CLOSEWINDOW,
  71.    WINDOWDEPTH | WINDOWCLOSE | WINDOWDRAG | SMART_REFRESH | REPORTMOUSE
  72.    | ACTIVATE | RMBTRAP,
  73.    NULL,
  74.    NULL,
  75.    (UBYTE *)BANNER,
  76.    NULL,
  77.    NULL,
  78.    0, 0, 0, 0,
  79.    WBENCHSCREEN } ;
  80. /*
  81.  *   This is the main initialize routine, which gets everything started
  82.  *   up.
  83.  */
  84. initialize() {
  85.    int i, j ;
  86. /*
  87.  *   First, we try and open libraries and windows.
  88.  */
  89.    if ((IntuitionBase = (struct IntuitionBase *)OpenLibrary(
  90.       "intuition.library",0L))==NULL ||
  91.        (GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0L))
  92.       ==NULL)
  93.       error("! Couldn't open libraries") ;
  94.    if (custscreen) {
  95.       mynewscreen.Width = GfxBase->NormalDisplayColumns ;
  96.       mynewscreen.Height = GfxBase->NormalDisplayRows ;
  97.       if ((myscreen=OpenScreen(&mynewscreen))==NULL)
  98.          error("! Couldn't open screen") ;
  99.       LoadRGB4(&(myscreen->ViewPort), colorTable, 4L) ;
  100.       mynewwindow.Screen = myscreen ;
  101.       mynewwindow.Type = CUSTOMSCREEN ;
  102.    }
  103.    if ((mywindow=OpenWindow(&mynewwindow))==NULL)
  104.       error("! Couldn't open window") ;
  105.    makepointer() ;
  106.    myrp = mywindow -> RPort ;
  107.    if (! custscreen) {
  108.       font = OpenFont(&myfont) ;
  109.       if (font != NULL)
  110.          SetFont(myrp, font) ;
  111.    }
  112.    allocbitmem() ;
  113.    buildgadgets() ;
  114.    drawlabels() ;
  115.    parseall() ;
  116. /*
  117.  *   Here we draw the bits array, hopefully for easy reference.
  118.  */
  119.    color(BLACK) ;
  120.    fbox(HBITSTART, VBITSTART, HBITSIZE, VBITSIZE) ;
  121.    color(WHITE) ;
  122.    box(HBITSTART, VBITSTART, HBITSIZE, VBITSIZE) ;
  123.    color(ORANGE) ;
  124.    for (i=1; i<24; i++)
  125.       box(HBITSTART + i * 24 - 2, VBITSTART, 2, VBITSIZE) ;
  126.    for (i=HBITSTART+4; i<HBITSTART+574; i += 6)
  127.       for (j=VBITSTART+3; j<VBITSTART+96; j += 3)
  128.          fbox(i, j, 1, 1) ;
  129.    color(BLUE) ;
  130.    box(HBITSTART, VBITSTART, HBITSIZE, VBITSIZE) ;
  131.    for (i=1; i<7; i++)
  132.       box(HBITSTART + i * 96 - 2, VBITSTART, 2, VBITSIZE) ;
  133.    for (i=1; i<9; i++)
  134.       line(HBITSTART, VBITSTART + i * 12, HBITSTART + HBITSIZE - 1,
  135.            VBITSTART + i * 12) ;
  136.    updatebits() ;
  137. /*
  138.  *   Now we draw boxes around the blitter register values and user
  139.  *   settable values.
  140.  */
  141.    color(WHITE) ;
  142.    box(HRVSTART, VRVSTART, HRVSIZE, VRVSIZE) ;
  143.    line(HMVSTART, VRVSTART, HMVSTART, VRVSTART + VRVSIZE - 1) ;
  144. }
  145. /*
  146.  *   This routine cleans up for exit.
  147.  */
  148. cleanup() {
  149.    if (font != NULL)
  150.       CloseFont(font) ;
  151.    if (mywindow != NULL) {
  152.       ClearPointer(mywindow) ;
  153.       CloseWindow(mywindow) ;
  154.    }
  155.    if (myscreen != NULL)
  156.       CloseScreen(myscreen) ;
  157.    if (GfxBase != NULL)
  158.       CloseLibrary(GfxBase) ;
  159.    if (IntuitionBase != NULL)
  160.       CloseLibrary(IntuitionBase) ;
  161.    freemem() ;
  162.    exit(0) ;
  163. }
  164. /*
  165.  *   Pointer routines.
  166.  */
  167. makepointer() {
  168.    short *pointer ;
  169.    int i ;
  170.  
  171.    pointer = allocmem((long)sizeof(pointerTable), MEMF_CHIP) ;
  172.    movmem(pointerTable, pointer, sizeof(pointerTable)) ;
  173.    SetPointer(mywindow, pointer, 15L, 15L, -7L, -7L) ;
  174. }
  175. /*
  176.  *   drawlabels() draws several miscellaneous labels all over the
  177.  *   screen.
  178.  */
  179. drawlabels() {
  180.    drawtext(HLMGSTART+4, VLMG3+2, "Adrs:") ;
  181.    drawtext(HLMGSTART+4, VLMG3+10, " M+") ;
  182.    drawtext(HLMGSTART+4, VLMG3+18, "Shift:") ;
  183.    drawtext(HRVC1 + 12, VRVL6, "Blitter Register Values") ;
  184.    drawtext(HRVC7 + 4, VRVLL6+1, "DMA Channels") ;
  185.    drawtext(HRVC1, VRVL1, "CON0") ;
  186.    drawtext(HRVC1, VRVL2, "CON1") ;
  187.    drawtext(HRVC1, VRVL3, "SIZE") ;
  188.    drawtext(HRVC1, VRVL4, "AFWM") ;
  189.    drawtext(HRVC1, VRVL5, "ALWM") ;
  190.    drawtext(HRVC3, VRVL2, "A") ;
  191.    drawtext(HRVC3, VRVL3, "B") ;
  192.    drawtext(HRVC3, VRVL4, "C") ;
  193.    drawtext(HRVC3, VRVL5, "D") ;
  194.    drawtext(HRVC4 + 4, VRVL1, "PTH  PTL  MOD  DAT") ;
  195.    drawtext(HRVC7, VRVLL2+1, "A") ;
  196.    drawtext(HRVC7, VRVLL3+1, "B") ;
  197.    drawtext(HRVC7, VRVLL4+1, "C") ;
  198.    drawtext(HRVC7, VRVLL5+1, "D") ;
  199.    drawtext(HRVC8, VRVLL1, "USE    PT     MOD          DAT          SH") ;
  200. }
  201.